package service

import (
	"fly/models"
	"github.com/beego/beego/v2/client/orm"
)

type SysRoleService struct {
	BaseService
}

// GetList 获取所有符合条件的chart
func (c *SysRoleService) GetList(filters ...CondFunc) []*models.SysRole {
	c.WhereField = append(c.WhereField, new(models.SysRole).WhereField()...)

	var orders []*models.SysRole
	qs := orm.NewOrm().QueryTable(new(models.SysRole))
	if len(c.WhereField) > 0 && len(filters) > 0 {
		cond := orm.NewCondition()
		for _, other := range filters {
			cond = other(cond)
		}
		qs = qs.SetCond(cond)
	}
	qs = qs.OrderBy("id")
	_, err := qs.All(&orders)
	if err != nil {
		return nil
	}
	return orders
}

func (c *SysRoleService) GetByRoleIds() (list []*models.SysRole, err error) {
	//if len(deptIdList) == 0 || isSuper {
	_, err = orm.NewOrm().QueryTable(new(models.SysRole)).All(&list)
	return
	//}
	//_, err = orm.NewOrm().QueryTable(new(models.SysRole)).Filter("dept_id__in", deptIdList).All(&list)
	//return
}
